package com.hackerrank.contests.sep13.challenges.starfleet;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Solution {
	private static class SpaceFighter implements Comparable<SpaceFighter> {
		int x, y, f;
		public SpaceFighter(int x, int y, int f) {
			this.x = x;
			this.y = y;
			this.f = f;
		}
		@Override
		public int compareTo(SpaceFighter sf) {
			return y - sf.y;
		}
		public String toString() {
			return "{x: " + x + ", y: " + y + ", f: " + f + "}";
		}
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt(), Q = in.nextInt(), V = in.nextInt();
		SpaceFighter sf[] = new SpaceFighter[N];
		for(int i = 0; i < N; i++)
			sf[i] = new SpaceFighter(in.nextInt(), in.nextInt(), in.nextInt());
		Arrays.sort(sf);
		for(int i = 0; i < Q; i++) {
			int YU = in.nextInt(), YD = in.nextInt(), T = in.nextInt();
			// binary search for YU
			int l = 0, u = sf.length - 1;
			while(l < u) {
				int m = (l + u) / 2;
				if(sf[m].y > YU)
					u = m - 1;
				else if(sf[m].y < YU)
					l = m + 1;
				else if(u == l + 1) {
					if(sf[m + 1].y == YU)
						l = m + 1;
					else
						u = m;
				}
				else
					l = m;
			}
			int su = u;
			// binary search for YD
			l = 0;
			while(l < u) {
				int m = (l + u) / 2;
				if(sf[m].y > YD)
					u = m - 1;
				else if(sf[m].y < YD)
					l = m + 1;
				else if(u == l + 1)
					u = m;
				else
					l = m;
			}
			int sl = l;
			// count frequencies
			HashMap<Integer, Integer> fc = new HashMap<Integer, Integer>();
			int mc = 0;
			for(int j = sl; j <= su; j++) {
				Integer v = fc.get(sf[j].f);
				int vv = v == null ? 1 : v + 1;
				if(vv > mc)
					mc = vv;
				fc.put(sf[j].f, vv);
			}
			System.out.println(mc);
		}
	}
}
